package io.gitee.zhangbinhub.admin.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import com.mybatisflex.annotation.Id
import com.mybatisflex.annotation.RelationManyToMany
import com.mybatisflex.annotation.Table
import io.gitee.zhangbinhub.admin.base.BaseTreeEntity
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import org.apache.commons.lang3.builder.EqualsBuilder
import org.apache.commons.lang3.builder.HashCodeBuilder
import org.noear.snack4.annotation.ONodeAttr

@Table("t_module_func")
@ApiModel("模块功能信息")
data class ModuleFunc(
    @Id
    @ApiModelProperty(name = "ID")
    var id: String = "",
    @ApiModelProperty(name = "应用ID")
    var appId: String = "",
    @ApiModelProperty(name = "模块名称")
    var name: String = "",
    @ApiModelProperty(name = "模块编码")
    var code: String = "",
    @ApiModelProperty(name = "是否可删除")
    var covert: Boolean = true,
    @JsonIgnore
    @field:ONodeAttr(ignore = true)
    @RelationManyToMany(
        joinTable = "t_role_module_func_set", // 中间表
        joinSelfColumn = "module_id",
        joinTargetColumn = "role_id"
    )
    var roleSet: MutableList<Role> = mutableListOf()
) : BaseTreeEntity<ModuleFunc>() {
    override fun equals(other: Any?): Boolean {
        if (other == null || javaClass != other.javaClass) return false
        if (this === other) return true
        val moduleFunc = other as ModuleFunc
        return EqualsBuilder()
            .appendSuper(super.equals(other))
            .append(id, moduleFunc.id)
            .append(appId, moduleFunc.appId)
            .append(name, moduleFunc.name)
            .append(code, moduleFunc.code)
            .append(covert, moduleFunc.covert)
            .append(parentId, moduleFunc.parentId)
            .isEquals
    }

    override fun hashCode(): Int =
        HashCodeBuilder(17, 37)
            .appendSuper(super.hashCode())
            .append(id)
            .append(appId)
            .append(name)
            .append(code)
            .append(covert)
            .append(parentId)
            .toHashCode()

    override fun toString(): String =
        StringBuilder("ModuleFunc(")
            .append("id=$id")
            .append(",appId=$appId")
            .append(",name=$name")
            .append(",code=$code")
            .append(",covert=$covert")
            .append(",parentId=$parentId")
            .append(")")
            .toString()
}
